package com.zmn.mcc.dubbo.impl.staff;

import com.alibaba.fastjson.JSONObject;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.mcc.business.interfaces.staff.StaffLoginBService;
import com.zmn.mcc.dubbo.dto.DubboConsts;
import com.zmn.mcc.dubbo.interfaces.staff.StaffLoginRemoteService;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

/**
 * @author heguanghua
 * @since 2020/06/11 16:51
 */
@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class StaffLoginRemoteServiceImpl implements StaffLoginRemoteService {
    private final Logger logger = LoggerFactory.getLogger(StaffLoginRemoteServiceImpl.class);

    private static final String TAG = "员工登录校验dubbo接口";

    @Resource
    private StaffLoginBService staffLoginBService;


    // region 员工登录基础校验

    @Override
    @ReadOnlyConnection
    public ResponseDTO checkLogin(String username, String password, String loginIP) {

        ResponseDTO response = staffLoginBService.checkLogin(username, password, loginIP);

        /**
         * 校验IP白名单
         * 如果不在"IP白名单"内
         */

        /**
         * 校验不限IP日期
         * 如果不在"不限IP日期"内
         */

        logger.info(String.format("[%s]校验员工登录,status:[%s],loginStaffDO:[%s],message:[%s]",
                TAG, response.getStatus(), (response.isSuccess() ? JSONObject.toJSONString(response.getData()) : "null"), response.getMessage()));
        return response;
    }
    // endregion
}
